﻿// See https://aka.ms/new-console-template for more information
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

Console.WriteLine("Hello, World!");

//socket创建
Socket socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//连接服务
socketClient.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8080));

byte[] msg = Encoding.ASCII.GetBytes("socket client data");
socketClient.Send(msg);


//接收数据
while (true)
{
    byte[] buffer = new byte[1024];
    int byteRec = socketClient.Receive(buffer);

    string data = Encoding.ASCII.GetString(buffer);
    Console.WriteLine("获取数据：" + data);
}
